﻿-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[spObtenDoctores](
	@psNombre VARCHAR(200),
	@pnIdDoctor INT,
	@pnIdLaboratorio INT
)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	IF @psNombre = ''
		SET @psNombre = NULL;

	SELECT	d.IdLaboratorio, d.IdDoctor, d.Nombre, d.Direccion, d.Telefono,
			u.UserName
	FROM	dbo.CatDoctor (NOLOCK) d
	LEFT JOIN RelUsuarioDoctor (NOLOCK) rud
	ON		d.IdDoctor = rud.IdDoctor
	LEFT JOIN CatUsuario u
	ON		rud.IdUsuario = u.IdUsuario
	WHERE	(d.Nombre LIKE '%' + @psNombre + '%' OR @psNombre IS NULL)
	AND		(d.IdDoctor = @pnIdDoctor OR @pnIdDoctor IS NULL)
	AND		d.IdLaboratorio = @pnIdLaboratorio;
	
	SET NOCOUNT OFF;
END
